package logic

import (
	"context"
	"fmt"
	"wechat/model/mysql"

	"wechat/wechatrpc/internal/svc"
	"wechat/wechatrpc/wechatrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MomentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMomentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MomentLogic {
	return &MomentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MomentLogic) Moment(in *wechatrpc.MomentRequest) (*wechatrpc.MomentResponse, error) {
	// todo: add your logic here and delete this line
	var pyq mysql.Moments
	mysql.DB.Debug().Where("user_id=?", in.UserId).Find(&pyq)

	if in.UserId == 0 {
		return nil, fmt.Errorf("账号为空,请重新输入")
	}

	data := mysql.Moments{
		UserId:  in.UserId,
		Title:   in.Title,
		Imag:    in.Imag,
		Content: in.Content,
		Times:   in.Times,
	}
	mysql.DB.Create(&data)
	return &wechatrpc.MomentResponse{
		UserId: int64(data.ID),
	}, nil
}
